import { resolve } from "path";
import { defineConfig, externalizeDepsPlugin } from "electron-vite";
import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";
import UnoCSS from "unocss/vite";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ArcoResolver, TDesignResolver } from "unplugin-vue-components/resolvers";
import monacoEditorPlugin from "vite-plugin-monaco-editor";
import { VueHooksPlusResolver } from "@vue-hooks-plus/resolvers";

export default defineConfig({
  main: {
    plugins: [externalizeDepsPlugin()],
    resolve: {
      alias: {
        "~": resolve("src/main"),
        $: resolve("src/core")
      }
    }
  },
  preload: {
    plugins: [externalizeDepsPlugin()]
  },
  renderer: {
    resolve: {
      alias: {
        "@": resolve("src/renderer/src"),
        $: resolve("src/core")
      }
    },
    plugins: [
      (typeof monacoEditorPlugin === "function"
        ? monacoEditorPlugin
        : // eslint-disable-next-line @typescript-eslint/ban-ts-comment
          // @ts-ignore
          monacoEditorPlugin.default)({}),
      vue(),
      vueJsx(),
      UnoCSS(),
      AutoImport({
        resolvers: [
          ArcoResolver(),
          TDesignResolver({
            library: "vue-next"
          }),
          VueHooksPlusResolver()
        ],
        imports: ["vue", "@vueuse/core", "vue-router"],
        eslintrc: {
          enabled: true
        }
      }),
      Components({
        resolvers: [
          ArcoResolver({
            sideEffect: true
          }),
          TDesignResolver({
            library: "vue-next"
          })
        ]
      })
    ],
    base: "./",
    // 强制预构建插件包
    optimizeDeps: {
      include: [
        "monaco-editor/esm/vs/language/json/json.worker",
        "monaco-editor/esm/vs/language/css/css.worker",
        "monaco-editor/esm/vs/language/html/html.worker",
        "monaco-editor/esm/vs/language/typescript/ts.worker",
        "monaco-editor/esm/vs/editor/editor.worker"
      ]
    },
    envDir: "env"
  }
});
